﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace Shsc.Net.Common.Security
{
    public class CryptoUtil
    {
        public static string CryptoString(String source)
        {
            MD5 md5Hasher = MD5.Create();
            byte[] data = md5Hasher.ComputeHash(Encoding.UTF8.GetBytes(source));
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < data.Length; i++)
            {
                sb.Append(data[i].ToString("X2"));
            }
            return sb.ToString();
        }

        public static bool CompareString(string source, string descStr)
        {
            StringComparer cp = StringComparer.OrdinalIgnoreCase;
            return 0 == cp.Compare(CryptoString(source), descStr);
        }
    }


}
